home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXT Education Software Sampler 1992 Fall
/
NeXT Education Software Sampler 1992 Fall.iso
/
SoundAndMusic
/
cmix
/
model.instruments
/
fm.c
next >
Wrap
C/C++ Source or Header
|
1992-01-27
|
2KB
|
54 lines
#include "../H/ugens.h"
#include "../macros/macros.h"
double fm(p,n_args)
float *p;
{
float sicar,simod,*xarray,*sine,val;
float evals[6],tabs[4],modphs,carphs;
float *risef,*decayf,index,amp,diff,val2;
int len1,len2,z,j;
int output,nsamps,i;
output = 1;
/* in Cmix pfields start with p0, which is the starting time */
/* p2 is pitch of carrier, p3 is pitch of mod, p4&5 index low&hi,
p6&7 rise and decay times p8 is amp, p9 is duration of envelope
on modulator index */
/* writes on cmix file 1 */
sine = floc(1); /* function 1 is sine wave */
xarray = floc(2); /* function 2 is index guide */
decayf = risef = floc(3); /*function 3 is envlp shape */
len1 = fsize(1); /* lookup size of f1 */
len2 = fsize(2); /* lookup size of f2 */
sicar = cpspch(p[2]) * len1/SR; /* convert cps to si */
simod = cpspch(p[3]) * len1/SR;
p[4] *= simod;
diff = (p[5] * simod) - p[4];
modphs = carphs = 0;
nsamps = setnote(p[0],p[1],output);
z = SR/200; /* interrupt 200 times per sec (control rate)*/
evset(p[1],p[6],p[7],3,evals); /* set overall envelope */
tableset(p[9],len2,tabs); /* set index envelope */
for(i=j=0; i<nsamps; i++) {
if(!j--) {
amp = evp(i,risef,decayf,evals) * p[8];
index = diff * tablei(i,xarray,tabs) + p[4];
j=z;
}
val= oscil(index,simod,sine,len1,&modphs);
val2= amp * osciln(1.,sicar+val,sine,len1,&carphs);
/* osciln allows negative sampling increment */
ADDOUT(&val2,output); /* additive writes */
}
endnote(output);
}